package org.jeecg.modules.xl.mpapi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.annotation.Export2Swagger;
import org.jeecg.modules.xl.as.entity.XlCustomerAs;
import org.jeecg.modules.xl.as.entity.XlCustomerAsDetail;
import org.jeecg.modules.xl.as.service.IXlCustomerAsService;
import org.jeecg.modules.xl.as.vo.ASAddRequest;
import org.jeecg.modules.xl.common.XlLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author deco
 * @create 2025-02-24
 */
@Api(tags="小程序-退款退货接口")
@RestController
@RequestMapping("/htmmp/as")
@Export2Swagger
@Slf4j
public class ASOrderController {

    @Resource
    private IXlCustomerAsService xlCustomerAsService;

    /**
     *
     * @param listType
     *
     */
    @Export2Swagger
    @ApiOperation(value = "获取售后单列表", notes = "获取售后单列表")
    @GetMapping(value = "/getASListByPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "listType", value = "列表类别", required = true, paramType = "query", dataType = "String",allowableValues="全部,进行中",allowMultiple=false),
            @ApiImplicitParam(name = "asCode", value = "售后单号", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "storeCode", value = "订单号", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNo", value = "当前页码", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "总页数", required = true, paramType = "query", dataType = "Integer"),
    })
    public Result<IPage<XlCustomerAs>> getASListByPage(@RequestParam(name = "listType", required = true) String listType,
                                                       @RequestParam(name = "asCode", required = false) String asCode,
                                                       @RequestParam(name = "storeCode", required = true) String storeCode,
                                                       @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        return Result.OK(xlCustomerAsService.getASListByPage(listType,asCode,storeCode,pageNo,pageSize));
    }

    @Export2Swagger
    @ApiOperation(value = "获取售后单明细", notes = "获取售后单明细")
    @GetMapping(value = "/getAsDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "asCode", value = "售后单编码", required = true, paramType = "query", dataType = "String"),
    })
    public Result<List<XlCustomerAsDetail>> getAsDetail(
                                                    @RequestParam(name = "asCode", required = true) String asCode) {
        return Result.OK(xlCustomerAsService.getAsDetailByASCode(asCode));
    }

    @Export2Swagger
    @ApiOperation(value = "新增售后单", notes = "新增售后单")
    @PostMapping(value = "/addAs")
    public Result<String> addAs(@RequestBody ASAddRequest asAddRequest) {

        return  xlCustomerAsService.addAs(asAddRequest);
    }

    @Export2Swagger
    @ApiOperation(value = "退货地址", notes = "退货地址")
    @GetMapping(value = "/getReturnAddress")
    public Result<Map> getReturnAddress(  @RequestParam(name = "storeCode", required = true) String storeCode,HttpServletRequest req) {
        Map<String,String> map = new HashMap<>();
        map.put("returnAddressId","1");
        map.put("returnAddress","广东省黄埔区永盛路30号C座2楼");
        map.put("returnPhone","17751142381");
        map.put("returnContact","好特麦退货");
        return  Result.ok(map);
    }

}